<section>
	<div class="page_title">
		<h2 class="fl">权限列表</h2>
        <a class="fr top_rt_btn iconfont iconfont-jia1" href="{:U('admin/Auth/addAuth')}">添加权限</a>
	</div>
	<table class="table">
		<tbody>
		<tr>
			<th>规则标识</th>
			<th>规则简述</th>
			<!--<th>附加条件</th>-->
			<th>所属模块</th>
			<th>状态</th>
			<th>操作</th>
		</tr>
		{volist name='data' id='v'}
		<tr>
			<td>{$v.name}</td>
			<td>{$v.title}</td>
			<!--<td>{$v.term}</td>-->
			<td>{$v.modulename}</td>
			<td>
				<input type="checkbox" id="checkbox_live{$i}" class="chk_4 conf_status rule_status" data-id="{:encrypt_id($v.id)}" data-lock="{$v.status}" {eq name='v.status' value='1'}checked{/eq} />
				<label for="checkbox_live{$i}">
					<input type="hidden" value="{$v.status}" />
				</label>
				<!--{if condition='!$v[status]'}<a class="inner_btn">关闭</a>{else/}<a class="inner_btn">开启</a>{/if}-->
			</td>
			<td>
				<div>
					<a class="green loadContent" href="{:U('admin/Auth/updateRule',array('id'=>encrypt_id($v.id)))}">
						<i class="iconfont iconfont-bianji inner_btn" style="color: #949496">&nbsp;编辑</i>
					</a>

					<a class="delAuth loadContent" data-id="{:encrypt_id($v.id)}" href="javascript:void(0)">
						<i class="iconfont iconfont-shanchu inner_btn" style="color: #949496">&nbsp;删除</i>
					</a>
				</div>
			</td>
		</tr>
		{/volist}
		</tbody>
	</table>
	<aside class="paging">
		{$page.html}
	</aside>
</section>
<script type="text/javascript">
	$('.rule_status').click(function () {
		var id = $(this).data('id');
		var lockid = $(this).data('lock') == 1 ? 1 : 0;
		if(lockid == 1)
		{
			var lock = 0;
		}else
		{
			var lock = 1;
		}
		send_data = {
			url:U('admin/Auth/ruleLock'),
			type:'POST',
			data:{
				id:id,
				lock:lock
			},
			dataType:'json',

		};
		send_ajax(send_data,function(res){
			if(res.status == 1){
				msg_success('操作成功','',2000);
				setTimeout(function(){
					admin.getContentByUrl(res.data.jumpurl);
				},2000);
			}else{
				msg_error(res.message);
			}
		})
	})
</script>
<script type="text/javascript">

$(".delAuth").click(function(){
	var id = $(this).data('id');
	msg({
		yes:'删除',
		no:'取消',
		txt:'确认删除?',
	},'question').then(function() {
		var send_data = {
			url:U('admin/Auth/deleteRule'),
			type:'POST',
			data:{
				id:id
			},
			dataType:'json',
		};
		send_ajax(send_data,function(response){
			if(response === false){
				DEBUG && admin.log(ajax_error);
				return false;
			}
			if(response.status == 1){
				msg_success(response.data.info,'',1000);
				setTimeout(function(){
					admin.getContentByUrl(response.data.jumpurl);
				},1000);
			}else{
				msg_error(response.message);
			}
			admin.log(response);
		});
	}, function(miss) {
		//dismiss can be 'cancel', 'overlay', 'close', 'timer'
		//if (miss === 'cancel') {
		//msg('你取消了')
		//}
	});
});
</script>
<script type="text/javascript">
	jQuery(function($) {
		$('table th input:checkbox').on('click' , function(){
			var that = this;
			$(this).closest('table').find('tr > td:first-child input:checkbox')
			.each(function(){
				this.checked = that.checked;
				$(this).closest('tr').toggleClass('selected');
			});
				
		});
	})
</script>